//
//  AppDelegate.swift
//  Test3
//
//  Created by 王冲 on 2019/1/31.
//  Copyright © 2019年 JK科技有限公司. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.rootViewController = UINavigationController(rootViewController: ViewController())
        window?.makeKeyAndVisible()
        
        return true
    }

    // 最新的
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        
        dealopenURL(url: url as NSURL)
        return true
    }
    
    // 被遗弃的(最好两个都用)
    func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        
        dealopenURL(url: url as NSURL)
        return true
    }
    
    // MARK:跳转的处理
    func dealopenURL(url:NSURL){
        
        let nav: UINavigationController! = window?.rootViewController as? UINavigationController
        
        nav.popToRootViewController(animated: false)
        
        let rootVC = nav.children[0]
        
        if url.path == "/vc2" {
            
            let vc2 = ViewController2()
            vc2.urlString = url.host
            rootVC.navigationController?.pushViewController(vc2, animated: true)
            
        }else if url.path == "/vc3"{
            
            let vc3 = ViewController3()
            vc3.urlString = url.host
            rootVC.navigationController?.pushViewController(vc3, animated: true)
        }
        
    }

}

